#include "DateTest.h"
#include <sstream>
#include <iostream>

namespace etu {

void DateTest::setUp() {
    this->date = new Date(2010, 3, 28);
}

void DateTest::tearDown() {
    delete this->date;
}

void DateTest::dateTest() {
    CPPUNIT_ASSERT_EQUAL(2010, this->date->getYear());
    CPPUNIT_ASSERT_EQUAL(3, this->date->getMonth());
    CPPUNIT_ASSERT_EQUAL(28, this->date->getDay());
}

void DateTest::unknownDateTest() {
    Date unknownDate = Date::unkown();

    CPPUNIT_ASSERT_EQUAL(true, Date::isUnkown(unknownDate));
    CPPUNIT_ASSERT_EQUAL(false, Date::isUnkown(* this->date));
}

void DateTest::serializationTest() {
    Date srcDate = * this->date;
    std::ostringstream oss;
    std::istringstream iss;

    oss << srcDate;
    iss.str(oss.str());

    Date* dstDate = new Date(2010, 4, 4);
    iss >> (* dstDate);

    CPPUNIT_ASSERT_EQUAL(true, (* dstDate) == srcDate);
}

}
